﻿using IBM.Data.DB2;
using System;
using System.Data.Common;

namespace CommonUtils
{
    /// <summary>
    /// ADO.NET for DB2
    /// </summary>
    public class DbDB2 : DbBase
    {
        public class ConnectStrings
        {
            //Database=MGWECHAT;User ID=db2inst;Password=db2inst;Server=x.x.x.x:x
            public static string Get(string host, string password, string database, int port = 5432)
            => string.Format("host={0};port={1};username=postgres;password={2};database={3};", host, port, password, database);
        }

        public DbDB2(string connectString)
        : base(connectString) { }

        public DbDB2(string host, string password, string database, int port = 5432)
        : this(ConnectStrings.Get(host, password, database, port)) { }

        protected override DbConnection GetConnection()
        => new DB2Connection(ConnectString);

        protected override DbParameter GetParameter(string key, object value)
        => new DB2Parameter(key, value);

        [Obsolete]
        protected override DbDataAdapter GetDataAdapter(DbCommand cmd)
        => new DB2DataAdapter((DB2Command)cmd);

        protected override char FieldStartIdentifier { get; } = '"';

        protected override char FieldEndIdentifier { get; } = '"';
    }
}
